/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef __XMLSTREAM_H__
#define __XMLSTREAM_H__

#include "Object.h"
#include <NoCopy.h>
#include <Converter.h>
#include <string>
#include <memory>

namespace liba
{
namespace resource { class Resource; }
namespace xml
{

class Provider
{
public:
	virtual bool parse_object(Object * obj)=0;
};

class Stream
{
public:
	virtual bool load(Object * obj)=0;
	
	virtual ~Stream()
	{}
};

class Root : public ObjectANSI, public ObjectUnicode
{
	Object * object;
	std::string nam;
	std::wstring wnam;
public:
	explicit Root( Object * object, const char * name)
		:	object( object )
	{
		nam = name;
	}

	explicit Root( Object * object, const std::string & name)
		:	object( object )
	{
		nam = name;
	}
	explicit Root( Object * object, const std::wstring & wname)
		:	object( object )
	{
		wnam = wname;
	}
	explicit Root( Object * object, const std::string & name, const std::wstring & wname)
		:	object( object )
	{
		nam = name;
		wnam = wname;
	}
	virtual bool on_node( Provider * prov, const std::string & name )
	{
		if( nam != name )
			return false;
		return prov->parse_object( object );
	}
	virtual bool on_node( Provider * prov, const std::wstring & name )
	{
		if( wnam != name )
			return false;
		return prov->parse_object( object );
	}
};

class StreamResourceImpl;

class StreamResource : public Stream, private Nocopy
{
public:
	explicit StreamResource( resource::Resource * res );
	virtual ~StreamResource();
	virtual bool load(Object * obj);
private:
	std::auto_ptr<StreamResourceImpl> impl;
};

} // namespace xml
} // namespace liba

using namespace liba;

#endif  //__XMLSTREAM_H__